<?php
//---------------------------------------------------------------------------------------------------
    include_once($config['smarty']['path'] . 'smarty.class.php');
    include_once($config['app_dir'] . '/includes/session.class.php');
    include_once($config['app_dir'] . '/classes/translation.class.php');
    //------------------------------------------------------------------------------------------------
    class objTemplate extends Smarty {
            protected $lang='en';

        function __construct($aLang=false) {
          global $config;
            parent::__construct();

            if( false!==$aLang ) $this->lang = strtolower($aLang);
                else {
                    $Session = new objSession($config['app_id']);
                    if( $Session->isExists('lang') ) $this->lang = $Session->Get('lang');
                }

            if( $config['smarty']['compile_dir'] )
               $this->compile_dir = $config['smarty']['compile_dir'];

            if( $config['smarty']['template_dir'] )
               $this->template_dir = $config['smarty']['template_dir'];

            if( $config['smarty']['config_dir'] )
                $this->config_dir = $config['smarty']['config_dir'];

            if( $config['smarty']['cache_dir'] )
                $this->cache_dir =  $config['smarty']['cache_dir'];

            if( is_bool($config['smarty']['compile_check']) )
                $this->compile_check =  $config['smarty']['compile_check'];

            $this->config_booleanize = false;
            $this->assign('lang', $this->lang);
        }//constructor

        function is_cached($tpl_file, $cache_id = null, $compile_id = null)   {
            if( !$this->caching ) return false;

            if( isset($cache_id) ) $cache_id = $this->lang . '-' . strval($cache_id);

            return parent::is_cached($tpl_file, $cache_id, $compile_id);
        }//is_cached

        function clear_cache($tpl_file = null, $cache_id = null, $compile_id = null, $exp_time = null) {
            if( isset($cache_id) ) $cache_id = $this->lang . '-' . strval($cache_id);
            return parent::clear_cache($tpl_file, $cache_id, $compile_id, $exp_time);
        }

        function fetch($resource_name, $cache_id = null, $compile_id = null, $display = false) {
            if( isset($cache_id) ) $cache_id = $this->lang . '-' . strval($cache_id);

            if( !$this->caching || $this->force_compile || ($this->caching>0 && !$this->is_cached($resource_name, $cache_id, $compile_id) ) ) {
                $path_parts = pathinfo($resource_name);
                $TranslationConf = objTranslationConf::GetInstance();
                $TranslationConf->RenderFile(substr($path_parts['basename'], 0, -4));
            }//is cache not set

            return parent::fetch($resource_name, $cache_id, $compile_id, $display);
        } //Fetch

    }//class objTemplate
//---------------------------------------------------------------------------------------------------
?>
